package util.adapter;

import android.app.Activity;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.TextView;

import com.amap.api.services.help.Tip;
import com.wq.cycling.R;

import java.util.ArrayList;
import java.util.List;

/**
 * poi搜索Adapter
 * author：wangqi on 2017/4/26 17:48
 * email：773630555@qq.com
 */

public class SearchAdapter extends BaseAdapter {

	private Activity mContext;
	private LayoutInflater mInflater;
	private List<Tip> mData;
	public SearchAdapter(Activity context, List<Tip> mData) {
		mContext = context;
		this.mData = new ArrayList<>();
		this.mData = mData;
		mInflater = LayoutInflater.from(mContext);
	}

	@Override
	public int getCount() {
		return mData.size();
	}

	@Override
	public Object getItem(int position) {
		return mData.get(position);
	}

	@Override
	public long getItemId(int position) {
		return position;
	}

	@Override
	public View getView(final int position, View convertView, ViewGroup parent) {
		ViewHolder holder;
		if (convertView == null) {
			convertView = mInflater.inflate(R.layout.listview_search_item,null);
			holder = new ViewHolder(convertView);
			convertView.setTag(holder);
		} else {
			holder = (ViewHolder) convertView.getTag();
		}
		holder.tv_title.setText(mData.get(position).getName());
		holder.tv_content.setText(mData.get(position).getDistrict()+mData.get(position).getAddress());
		return convertView;
	}

	private static class ViewHolder {
		public TextView tv_title,tv_content;
		public View ll_linear;
		ViewHolder(View view) {
			tv_title = ((TextView) view.findViewById(R.id.tv_title));
			tv_content = ((TextView) view.findViewById(R.id.tv_content));
			ll_linear = view.findViewById(R.id.ll_linear);
		}
	}
}
